package top.tupobi.zing.base;

import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import top.tupobi.zing.mvp.presenter.ChatPresenter;
import top.tupobi.zing.utils.StatusBarUtil;
import top.tupobi.zing.utils.ThemeUtil;


public abstract class BaseMVPActivity<T extends IBasePresenter> extends AppCompatActivity implements IBaseView, View.OnClickListener {

    protected T mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setLayout();
        ThemeUtil.setStatusBar(this);
        StatusBarUtil.setTitleStatusBarColor(this);
        mPresenter = createPresenter();
        if (null == mPresenter) {
            throw new IllegalStateException("Please call mPresenter in BaseMVPActivity(createPresenter) to create!");
        } else {
            mPresenter.attach(this);
        }
        viewCreated();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (null != mPresenter) {
            mPresenter.detach();
        }
    }

    protected abstract void initView();

    protected abstract void process();

    protected void setLayout() {
        setContentView(inflateContentView());
    }

    protected abstract int inflateContentView();

    protected abstract T createPresenter();

    protected final void viewCreated() {
        initView();
        setViewListener();
        process();
    }

    protected abstract void setViewListener();

    @Override
    public final void toast(String msg) {
        ToastUtils.showShort(msg);
    }


    @Override
    public void finishCurrentAty() {
        finish();
    }
}